#include <bits/stdc++.h>
#include <stdexcept>
#include <string>
using namespace std;

class Solution {
public:
    int evalRPN(vector<string>& tokens) {
        stack<int> stk;
        for(auto& token:tokens){
            int x;
            try{
                x = stoi(token);
            }
            catch(std:: invalid_argument&){
                int b = stk.top(); stk.pop();
                int a = stk.top(); stk.pop();
                if(token == "+") x = a+b;
                else if(token == "-") x = a-b;
                else if(token == "*") x = a*b;
                else if(token == "/") x = a/b;
            }
            stk.push(x);
        }
        return stk.top();
    }
};